package com.brunogb.pages.server.services;

import com.brunogb.pages.database.repository.PageRepository;
import com.brunogb.pages.exceptions.RepositoryException;
import com.brunogb.pages.server.model.Page;

public class PageServiceImpl {

	PageRepository repo = new PageRepository();
	
	public int getTotalCountPages(){
		try {
			return repo.count();
		} catch (RepositoryException e) {
			e.printStackTrace();
			return -1;
		}
	}
	
	public Page findPage(String pageName){
		try {
			return repo.find(pageName);
		} catch (RepositoryException e) {
			System.out.println(e.getMessage());
			return null;
		}
	}
	
	public Page save(Page p){
		try {
			repo.save(p);
			return p;
		} catch (RepositoryException e) {
			e.printStackTrace();
			return null;
		}
	}
	
}
